<?php 
//引入函数库
include "./function.php";
//引入数据库
$data=include "./data.php";
//开启对话
session_start();
//判定上传的方式是否是post
	if(IS_POST){
//		先判定验证码
		if($_POST['code']!=$_SESSION['code']){
			success('验证码不正确', './'); 
		}
//		再判定post提交的数据是否与数据库的数据相等
//		使用foreach循环得到数据库里面的数据，然后跟上传的数据进行比较
//		p($data);die;
		foreach($data as $v){
//			用提交上来的账号到数据库里匹配
			if($_POST['ID']==$v['ID']){
//				把匹配到的新变量赋值到一个新的变量中
				$newdata=$v;
			}
		}
//			判断$newdata是否存在
			if(!$newdata){
//				如果不存在就输出
				success('账号不存在');
			}
//			判定用户上传的密码是否与数据库里面的相同
			if(md5($_POST['password'])!=$newdata['password']){
				success('密码不正确', './');
			}
//		添加sessionid
			$_SESSION['id']=1;
//			让欢迎页面显示昵称
			$_SESSION['name']=$v['nickname'];
		success('登陆成功','./login.php');
	}
 ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<script src="jquery-1.7.2.min.js" type="text/javascript" charset="utf-8"></script>
	<title>登陆页面</title>
	<script type="text/javascript">
		$(function(){
			$('#change').click(function(){
				var src=$('.code').attr('src');
				var fulldest=src+'?'+Math.random();
				$('.code').attr('src',fulldest);
			})
		})
	</script>
	<style type="text/css">
		*{
			padding: 0;
			margin: 0;
		}
		li{
			list-style: none;
		}
		body{
			width: 1200px;
			height: 700px;
			background: url(image/01.jpg) no-repeat 0px 0px;
			background-size:100%;
			position: relative;
		}
		#box{
			width: 420px;
			height:565px;
			/*border: 1px solid red;*/
			position: absolute;
			top:50px;
			right:10px;
			background:#A6A6A6;
			opacity: 0.8;
		}
		#box .title{
			width: 420px;
			height: 160px;
			line-height:60px;
			border-bottom: 1px solid #666666;
			text-align: center;
		}
		#box .title .t1{
			text-decoration: none;
			font-size: 40px;
			font-weight:700;
			color: #040308;
		}
		#box form .neirong li{
			width: 380px;
			height: 45px;
			line-height: 50px;
			margin-left:20px;
		}
		#box form .neirong li span{
			font-size: 20px;
			font-family: "微软雅黑";
			color: #D84C29;
		}
		#box form .neirong li input{
			width: 223px;
			height: 30px;
			border: none;
			border-bottom:1px dashed red ;
			margin-left: 10px;
			background:#A6A6A6 ;
		}
		#box form .denglu{
			width: 170px;
			height: 46px;
			/*border: 1px solid #002A80;*/
			position: absolute;
			bottom: 0px;
			right: 10px;
			opacity:0.9;
			cursor: pointer;
			
		}
		#box form .zhuce{
			display: block;
			width: 170px;
			height: 46px;
			line-height: 46px;
			text-align: center;
			text-decoration: none;
			font-size: 30px;
			font-family: "微软雅黑";
			background: white;
			position: absolute;
			bottom: 0px;
			left:10px;
			opacity:0.9;
			cursor: pointer;
			color: black;
		}
		#box form img{
			display: block;
			width: 130px;
			height: 70px;
			/*border: 1px solid red;*/
			position: absolute;
			top: 200px;
			left: 80px;
		}
		#box form #change{
			display: block;
			width: 105px;
			height: 26px;
			position: absolute;
			top: 230px;
			left: 220px;
			font-size: 15px;
		}
		
	</style>
</head>
<body>
	<!--登陆主体框架-->
	<div id="box">
		<!--登陆界面-->
		<div class="title">
			<img src="image/04.jpg" style="width: 420px;height: 160px;"/>
			<!--<a href="" class="t1">登录</a>-->
		</div>
		<!--登陆口-->
		<form action="" method="post" style="width:380px;height:383px;margin-top:15px; margin-left: 17px;position: relative;">
			<ul class="neirong">
				<li><span>昵称:<input type="text" name="nickname" id="nickname" value="" /></span></li>
				<li><span>账号：</span><input type="text" name="ID" id="" value="" /></li>
				<li><span>密码:</span><input type="password" name="password" id="" value="" /></li>
				<li><span>验证码:</span><input type="text" name="code" id="" value="" /></li>
				<img src="./Code.class.php" onclick="this.src=this.src+'?'+Math.random()" alt="" class="code"/>
				<a href="javascript:;" id="change">看不清换一个</a><br />
			</ul>
			<input type="submit" value="登录游戏" class="denglu" style="font-size:25px;font-family:'微软雅黑';background:#F5F6F7 ;"/>
			<a href="./register.php" class="zhuce">注册账号</a>
			<ul class="fuxuan" style="width: 210px;height: 21px;position: absolute;top: 300px;left: 50px;">
				<li style="float: left;line-height: 21px;"><input type="checkbox" name="" id="" value="" style="width: 17px;height: 17px;"><span class="rember">记住密码</span></li>
				<li style="float: right;line-height: 21px;"><input type="checkbox" name="" id="" value="" style="width: 17px;height: 17px;"/><span class="auto">自动登录</span></li>
			</ul>
		</form>
	</div>
</body> 
</html>





